
let postUrl = 'http://121.43.153.61:9090';
let token = 'Bearer ' + window.GlobalToken


function getTab(){
    var tab_list = document.querySelector('.tab_list');
    var lis = tab_list.querySelectorAll('li');
    var items = document.querySelectorAll('.item');
    
    for (var i = 0;i < lis.length;i++) {
        lis[i].setAttribute('index',i);
        lis[i].onclick = function() {
            for (var i = 0;i < lis.length;i++) {
                lis[i].className = '';
            }
            this.className = 'red';
            var index = this.getAttribute('index');
            for (var i = 0;i < items.length;i++) {
                items[i].style.display = 'none';
            }
            items[index].style.display = 'block';
        }
    }    
}

function getInfo(){
    $.ajax({
        url: postUrl + "/api/v1/login/getInfo",
        method: 'get',
        // 通过headers对象设置请求头
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        data: {},
        dataType: 'json',
        //async: true,
        success: function (res) {
          if (res.code === 200) {
            let info = res.data.user
            let content = document.querySelector('#info')
            let listStr = ''
              listStr += `<div class="top_l">
        <img src="${info.avatar}" alt="" class="top_l_img" />
      </div>
      <div class="top_r" id="top_r">
        <div class="name">${info.username}</div>
        <div class="money">剩余金币：${info.coins}</div>
        <div class="time">创建时间：${info.createTime}</div>
      </div>`
            content.innerHTML = listStr
          }
        },
        error: function (e) {
        }
      })
}
function gameRecord(){
    $.ajax({
        url: postUrl + "/api/v1/center/record/game",
        method: 'get',
        // 通过headers对象设置请求头
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        data: {},
        dataType: 'json',
        //async: true,
        success: function (res) {
          if (res.code === 200) {
           let list = res.rows
           let content = document.querySelector('#game')
           let listStr = ''
           list.forEach((item, index) => {
             listStr += `
               <div class="list_item">
            <img src="${item.clientGameVo.cover}" alt="" class="list_item_img" />
            <div class="list_foo">
              <div class="list_foo_name">${item.gameName}</div>
              <div class="list_foo_type">${item.clientGameVo.type}</div>
            </div>
          </div>`
           })
           content.innerHTML = listStr

          }
        },
        error: function (e) {
        }
      })
}
function shopRecord(){
    $.ajax({
        url: postUrl + "/api/v1/center/record/shop",
        method: 'get',
        // 通过headers对象设置请求头
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        data: {},
        dataType: 'json',
        //async: true,
        success: function (res) {
          if (res.code === 200) {
            let list = res.rows
           let content = document.querySelector('#shop')
           let listStr = ''
           list.forEach((item, index) => {
             listStr += `
             <ul class="purchase_list_item" >
    <li>${item.shopName}</li>
            <li>${item.coins}金币</li>
            <li>${item.createTime}</li>
          </ul>
           `
           })
           content.innerHTML = listStr
          }
        },
        error: function (e) {
        }
      })
}
function rechargeRecord(){
    $.ajax({
        url: postUrl + "/api/v1/center/record/shop/recharge",
        method: 'get',
        // 通过headers对象设置请求头
        headers: { 'Content-Type': 'application/json', 'Authorization': token },
        data: {},
        dataType: 'json',
        //async: true,
        success: function (res) {

          if (res.code === 200) {
            let list = res.rows
            let content = document.querySelector('#recharge')
            let listStr = ''
            list.forEach((item, index) => {
              listStr += `
              <ul class="recharge_list_item">
               <li>${item.price}</li>
             <li>${item.coins}金币</li>
             <li>${item.createTime}</li>
            </ul>
          
              `
            })
            content.innerHTML = listStr
          }
        },
        error: function (e) {
        }
      })
}
getInfo()
gameRecord()
shopRecord()
rechargeRecord()
getTab()
